import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/attendance/attAskforleave/list',
  save='/attendance/attAskforleave/add',
  edit='/attendance/attAskforleave/edit',
  deleteOne = '/attendance/attAskforleave/delete',
  deleteBatch = '/attendance/attAskforleave/deleteBatch',
  importExcel = '/attendance/attAskforleave/importExcel',
  exportXls = '/attendance/attAskforleave/exportXls',
  listBase = '/attendance/attAskforleave/listBase',
  channelRelease = '/channel/acTemporaryGeneral/channelRelease',
  countLeave = '/attendance/attAskforleave/countLeave',
  listAudit = '/attendance/attAskforleave/listAudit',
  auditReq =  '/attendance/attAskforleave/audits',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
export const listAudit = (params) =>
  defHttp.get({url: Api.listAudit, params});

export const listBase = (params) =>
  defHttp.get({url: Api.listBase, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
export const auditReq = (params) => {
  let url = Api.auditReq;
  return defHttp.post({url: url, params});
}
export const channelRelease = (params) => {
  let url =Api.channelRelease;
  return defHttp.post({url: url, params});
}
export const countLeave = (params) => {
  let url =Api.countLeave;
  return defHttp.post({url: url, params});
}


